﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using BobbyCore;
using System.Data.Common;
using System.Data.OleDb;
using Bobby.Entity.Common;
using System.Data.SqlClient;

namespace Dao
{
    public class DealWith
    {
        public DealWith()
        { }
        #region 家庭理财系统

        private const string userlogin = @"select loginname,loginpass from login where loginname=@loginname and loginpass=@loginpass";
        private const string selectall = @"select ID,C_BigType,C_SmallType,C_Money,C_Date from Detail";
        private const string query = @"select ID,C_BigType,C_SmallType,C_Money,C_Date from Detail where C_BigType like @title";
        private const string delete = @"delete from Detail where ID=@ID";
        private const string selectSingle = @"select ID,C_BigType,C_SmallType,C_Money,C_Date from Detail where ID=@ID";
        private const string insert = @"insert into Detail(C_BigType,C_SmallType,C_Money,C_Date)  values(@C_BigType,@C_SmallType,@C_Money,@C_Date)";
        private const string update = @"update Detail set C_BigType=@C_BigType,C_SmallType=@C_SmallType,C_Money=@C_Money,C_Date=@C_Date where ID=@ID";
        

        public bool UserLogin(string loginname, string loginpass)
        {
            DbParameter[] para =
           {
                   new OleDbParameter("@loginname",OleDbType.LongVarChar,20){Value=loginname}
                  ,new OleDbParameter("@loginpass",OleDbType.LongVarChar,20){Value=loginpass}

                
            };
            //  return new Operation().ExNoQuery(CommandType.Text,userlogin, para)>0;
            return new Operation().ExScalar(CommandType.Text, userlogin, para) != null;
        }
        public DataTable SelectALL()
        {
            return new Operation().DS(CommandType.Text, selectall).Tables[0];
        }
        public DataTable Query(string title)
        {
            DbParameter[] para =
           {
                   new OleDbParameter("@title",OleDbType.LongVarChar,20){Value=title}

            };
            return new Operation().DS(CommandType.Text, query, para).Tables[0];
        }
        public bool Delete(string ID, ref DbTransaction dbt)
        {
            DbParameter[] para =
           {
                    new OleDbParameter("@ID",OleDbType.BigInt,8){Value=Int64.Parse(ID)}
                 
            };
            return new Operation().ExNoQuery(CommandType.Text, delete, para, ref dbt) > 0;
        }
        public bool Insert(Detail model,ref DbTransaction dbt)
        {
            DbParameter[] para =
           {
                     new OleDbParameter("@C_BigType",OleDbType.Char,20){Value=model.C_BigType}
                   , new OleDbParameter("@C_SmallType",OleDbType.Char,20){Value=model.C_SmallType}
                   , new OleDbParameter("@C_Money",OleDbType.Single){Value=model.C_Money}
                   ,new OleDbParameter("@C_Date",OleDbType.Date){Value=model.C_Date}
                 
            };

            return new Operation().ExNoQuery(CommandType.Text, insert,para,ref dbt) > 0;
        }
        public bool Update(Detail model,ref DbTransaction dbt)
        {
            DbParameter[] para =
           {      
                    new OleDbParameter("@C_BigType",OleDbType.Char,20){Value=model.C_BigType}
                   ,new OleDbParameter("@C_SmallType",OleDbType.Char,20){Value=model.C_SmallType}
                   ,new OleDbParameter("@C_Money",OleDbType.Single){Value=model.C_Money}
                   ,new OleDbParameter("@C_Date",OleDbType.Date){Value=model.C_Date}
                   ,new OleDbParameter("@ID",OleDbType.BigInt){Value=model.ID}
                 
            };

            return new Operation().ExNoQuery(CommandType.Text, update, para, ref dbt)>0;         

        }
        public DataTable SelectSingle(string ID)
        {
            DbParameter[] para =
           {
                    new OleDbParameter("@ID",OleDbType.BigInt,20){Value=ID}

            };
            return new Operation().DS(CommandType.Text, selectSingle, para).Tables[0];
        }
        #endregion
    }
}
